package com.cn.boot.student.controller.student.team;
import com.cn.boot.student.entity.TeamEntity;
import com.cn.boot.student.service.team.ITeamService;
import com.cn.boot.student.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小组管理控制器
 *
 * @author luosir
 */
@RestController
@RequestMapping("/admin/team")
@Api(tags = "小组管理")
public class TeamController {
    @Autowired
    private ITeamService iTeamService;

    /**
     * 小组列表,分页，条件查询
     */
    @PostMapping("/findAll")
//    @PreAuthorize("hasAuthority('sys:team:read')")
    @ApiOperation(value = "小组列表")
    public CommonResult findAll( TeamEntity teamEntity) {
        return iTeamService.findAll(teamEntity);
    }

    /***
         * 小组添加
     * @param teamEntity
     * @return
     */

    @PostMapping("/add")
    @PreAuthorize("hasAuthority('sys:team:add')")
    @ApiOperation(value = "小组添加")
    public CommonResult add(TeamEntity teamEntity) {
        return iTeamService.add(teamEntity);
    }

    /**
     *小组更新
     * @param teamEntity
     * @return
     */
    @PostMapping("/update")
    @PreAuthorize("hasAuthority('sys:team:update')")
    @ApiOperation(value = "小组更新")
    public CommonResult update(TeamEntity teamEntity) {
        return iTeamService.update(teamEntity);
    }

    /***
     * 删除小组
     * @param id
     * @return
     */
    @DeleteMapping("/del")
    @PreAuthorize("hasAuthority('sys:team:del')")
    @ApiOperation(value = "小组列表")
    public CommonResult del(Integer id) {
        return iTeamService.del(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/dels")
    @PreAuthorize("hasAuthority('sys:team:del')")
    @ApiOperation(value = "小组列表")
    public CommonResult dels(List<Integer> ids) {
        return iTeamService.dels(ids);
    }

    /**
     * 小组分配学员
     * @param teamEntity
     * @return
     */
    @PostMapping("/assignStudent")
    @PreAuthorize("hasAuthority('sys:team:assignStudent')")
    @ApiOperation(value = "小组分配学员")
    public CommonResult assignStudent(TeamEntity teamEntity) {
        return iTeamService.assignStudent(teamEntity);
    }

    /**
     * 根据id查询小组信息
     * @param id
     * @return
     */
    @PostMapping("/findById")
    @PreAuthorize("hasAuthority('sys:team:read')")
    @ApiOperation(value = "根据id查询小组信息")
    public CommonResult findById(Integer id) {
        return iTeamService.findById(id);
    }

    @GetMapping("/findAllCoach")
    @ApiOperation(value = "得到所有角色为教练的用户")
    public CommonResult findAllCoach(){
        return iTeamService.findAllCoach();
    }
    @GetMapping("/findAllLeader")
    @ApiOperation(value = "得到所有角色为组长的用户")
    public CommonResult findAllLeader(){
        return iTeamService.findAllLeader();
    }

    /**
     * 得到已经分配小组的学员
     * @return
     */
    @GetMapping("/getIsAssignStudent")
    @PreAuthorize("hasAuthority('sys:team:read')")
    @ApiOperation(value = "得到已经分配小组的学员")
    public CommonResult getIsAssignStudent(TeamEntity teamEntity){
        return iTeamService.getIsAssignStudent(teamEntity);
    }

    /**
     * 得到未分配小组的学员
     * @return
     */
    @GetMapping("/getNoAssignStudent")
    @PreAuthorize("hasAuthority('sys:team:read')")
    @ApiOperation(value = "得到未分配小组的学员")
    public CommonResult getNoAssignStudent(TeamEntity teamEntity){
        return iTeamService.getNoAssignStudent(teamEntity);
    }

}
